<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>RVM : Coding Conventions</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            RVM : Coding Conventions
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Jul 03, 2008 by <font color="#0050B2">dgrove</font>.
				    </div>

				    <h3><a name="CodingConventions-Assertions"></a>Assertions</h3>

<p>Partly for historical reasons, we use our own built-in assertion facility rather than the one that appeared in Sun®'s JDK 1.4.   All assertion checks have one of the two forms:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">if</span> (VM.VerifyAssertions)  VM._assert(condition)
    <span class="code-keyword">if</span> (VM.VerifyAssertions)  VM._assert(condition,  message)</pre>
</div></div>
<p><tt>VM.VerifyAssertions</tt> is a <tt>public static final</tt> field.  The <tt>config.assertions</tt> configuration variable determines <tt>VM.VerifyAssertions</tt>' value. If <tt>config.assertions</tt> is set to <tt>none</tt>, Jikes RVM has no assertion overhead.<br/>
If you use the form without a <em>message</em>, then the default message "<tt>vm internal error at:</tt>"  will appear.</p>

<p>If you use the form with a <em>message</em> the message <em>must</em> be a single string literal.  Doing string appends in assertions can be a source of horrible performance problems when assertions are enabled (i.e. most development builds).  If you want to provide a more detailed error message when the assertion fails, then you must use the following coding pattern:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">if</span> (VM.VerifyAssertions &amp;&amp;  condition) VM._assert(<span class="code-keyword">false</span>,  message);</pre>
</div></div>
<p>An assertion failure is always followed by a stack dump.</p>

				    
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="http://docs.codehaus.org/images/border/border_bottom.gif"><img src="images/border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Jun 10, 2009 09:12</font></td>
		    </tr>
	    </table>
    </body>
</html>